package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.ConversionRecordBean;
import com.lc.pianostudent.bean.PianoIndexBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.GETRECORD)
public class PostGetRecord extends BaseAsyPost {

    public String user_id,page;
    public PostGetRecord(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostGetRecordInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostGetRecordInfo info = new PostGetRecordInfo();

            info.code = object.optString("code");

            JSONObject jsonObject = object.optJSONObject("data");
            info.total = jsonObject.optInt("total");
            info.per_page = jsonObject.optInt("per_page");
            info.current_page = jsonObject.optInt("current_page");
            info.last_page = jsonObject.optInt("last_page");

            JSONArray array = jsonObject.optJSONArray("data");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    ConversionRecordBean conversionRecordBean = new ConversionRecordBean();
                    conversionRecordBean.setCreatetime(o.optString("createtime"));
                    conversionRecordBean.setText(o.optString("text"));

                    info.list.add(conversionRecordBean);
                }

            }


            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostGetRecordInfo {

        public String code;
        public int total, per_page ,current_page,last_page;
        public List<ConversionRecordBean> list = new ArrayList<>();
    }

}
